{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 简单线性回归（最小二乘法）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 0. 引入依赖"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1. 导入数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD4CAYAAAAXUaZHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAauUlEQVR4nO3df4xdZZ3H8feX6SAD6zoCEwJTamsk06gVihPEdGOk6BaFQFONQmQXlU3/WLPrurvVNmvWZaPbmu4G2WxW08UfbHChWGrxx8ZKKMaECGS6BSs/uiBI6fCjNVA2wgjT9rt/3HPp/Lg/zr3n13PO+bySZuaeuXPnuWc63/M83+f7PMfcHRERqZYTim6AiIikT8FdRKSCFNxFRCpIwV1EpIIU3EVEKmhB0Q0AOP30033x4sVFN0NEpFR27979W3cfafW1IIL74sWLmZiYKLoZIiKlYmZPtfua0jIiIhWk4C4iUkFdg7uZfcvMDprZr2Yc22xmj5rZL83s+2Y2PONrG8zscTPbZ2arsmq4iIi0F6fn/h3gkjnH7gTe6e7vAv4X2ABgZm8HrgTeEX3Pv5vZQGqtFRGRWLoGd3f/OfDCnGM/dfcj0cN7gYXR51cAt7r7q+7+JPA4cEGK7RURkRjSqJb5NLA1+nyURrBvOhAdm8fM1gJrARYtWpRCM0RE4tmxZ5LNO/fxzOEpzhoeYt2qMVYvbxmqSivRhKqZ/R1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sNmts3MHjWzR8zsvXU8H2Y2Fv2faP77PzP7q6zPhYJ7714FVrr7ucB5wCVmdiHwVeB6d38b8CJwbYFtzNtngUdmPK7zubjI3c+bUcO8HrjL3c8B7ooe18UNwE/cfSlwLo3/I7U7H+6+L/o/cR7wbuAV4PtkfC4U3HvkDb+LHg5G/xxYCWyLjt8ErC6gebkzs4XApcCN0WOjpueijStonAOo0bkwszcB7wO+CeDur7n7YWp6Pma4GPi1uz9FxudCwb0PURriAeAgcCfwa+Cwux+JnnIAqMsdOL4GfB44Fj0+jfqeCwd+ama7zWxtdOwMd382+vw54Iximpa7JcAh4NtRyu5GMzuF+p6PpiuBW6LPMz0XCu59cPej0RBrIXABsLTgJhXCzC4DDrr77qLbEog/cvfzgQ8BnzGz9838ojfqjutSe7wAOB/4ursvB15mTtqhZueDaO7pcuB7c7+WxblQcE8gGmbeDbwXGDaz5m0LFwKThTUsPyuAy83sN8CtNNIxN1DPc4G7T0YfD9LIqV4APG9mZwJEHw8W18JcHQAOuPt90eNtNIJ9Xc8HNC76/+Puz0ePMz0XCu49MrMRMxuOPh8CPkhjouhu4KPR064B7iimhflx9w3uvtDdF9MYbu5y909Qw3NhZqeY2RubnwN/DPwK+AGNcwA1ORcA7v4c8LSZjUWHLgYepqbnI3IVx1MykPG50ArVHpnZu2hMfgzQuDje5u7/aGZvpdF7PRXYA1zt7q8W19J8mdn7gb9198vqeC6i9/z96OEC4L/c/StmdhpwG7CIxrbWH3P3FwpqZq7M7DwaE+0nAk8AnyL6m6Fm5yO64O8H3uruL0XHMv2/oeAuIlJBSsuIiFSQgruISAUpuIuIVJCCu4hIBSm4i4hUkIK7iEgFKbiLiFTQ/wN8F0LjPjEAqgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "points = np.genfromtxt('data.csv', delimiter=',')\n",
    "\n",
    "# 提取 points 中的两列数据， 分别为 x, y\n",
    "x = points[:, 0]\n",
    "y = points[:, 1]\n",
    "\n",
    "# 用 plt 画出散点图\n",
    "plt.scatter(x, y)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2. 定义损失函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 损失函数是系数的函数，另外还需要传入数据的 x,y\n",
    "def compute_cost(w, b, points):\n",
    "    total_cost = 0\n",
    "    M = len(points)\n",
    "\n",
    "    # 逐点计算平方损失误差，然后求平均数\n",
    "    for i in range(M):\n",
    "        x = points[i, 0]\n",
    "        y = points[i, 1]\n",
    "        total_cost += ( y - w * x - b ) ** 2\n",
    "  \n",
    "    return total_cost/M"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3. 定义算法拟合函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 先定义一个求均值的函数\n",
    "def average(data):\n",
    "    sum = 0\n",
    "    num = len(data)\n",
    "    for i in range(num):\n",
    "        sum += data[i]\n",
    "    return sum/num\n",
    "\n",
    "# 定义核心拟合函数\n",
    "def fit(points):\n",
    "    M = len(points)\n",
    "    x_bar = average(points[:, 0])\n",
    "    \n",
    "    sum_yx = 0\n",
    "    sum_x2 = 0\n",
    "    sum_delta = 0\n",
    "\n",
    "    for i in range(M):\n",
    "        x = points[i, 0]\n",
    "        y = points[i, 1]\n",
    "        sum_yx += y * ( x - x_bar)\n",
    "        sum_x2 += x ** 2\n",
    "    # 根据公式计算\n",
    "    w = sum_yx / ( sum_x2 - M * (x_bar ** 2) )\n",
    "    \n",
    "    for i in range(M):\n",
    "        x = points[i, 0]\n",
    "        y = points[i, 1]\n",
    "        sum_delta += (y - w * x)\n",
    "    b = sum_delta / M\n",
    "    \n",
    "    return w, b"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4. 测试"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "w is:  1.3224310227553846\n",
      "b is:  7.991020982269173\n",
      "cost is:  110.25738346621313\n"
     ]
    }
   ],
   "source": [
    "w, b = fit(points)\n",
    "print('w is: ', w)\n",
    "print('b is: ', b)\n",
    "\n",
    "cost = compute_cost(w, b, points)\n",
    "\n",
    "print('cost is: ', cost)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5. 画出拟合曲线"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD4CAYAAAAXUaZHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nO3de5hcVZnv8e+bTostIm0gMtAhpFEmiAZIbEGNCiFouEToiR4uj3AYYCbyDOMgxxOTzHFU5gmTYJSLozIyoKJGAiJ0MAgxJjA4UcJ0aDIhhjiBhJDmFgyNQhrodNb5Y1elq6v3ruuu2pf6fZ4nT3ftqtq1enf63Wu/611rm3MOERFJl1FRN0BERMKn4C4ikkIK7iIiKaTgLiKSQgruIiIpNDrqBgAcfPDBbsKECVE3Q0QkUdatW/eSc26s33OxCO4TJkygu7s76maIiCSKmT0d9JzSMiIiKaTgLiKSQkWDu5l938xeNLPHc7YtNrMnzOy/zexuM2vNeW6+mW0xs81mNqNWDRcRkWCl9Nx/CJyWt20l8H7n3LHAH4D5AGZ2DHAe8L7Me75rZk2htVZEREpSNLg75x4CduVt+5Vzbk/m4cPAuMz3ZwNLnXNvOOe2AluAE0Jsr4iIlCCMaplLgNsz37fhBfusHZltI5j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MZeYDwIeBVjPL3rZwHNAbWcPqZypwlpltA5bipWNuoDGPBc653szXF/FyqicAL5jZoQCZry9G18K62gHscM6tzTy+Ey/YN+rxAO+k/6hz7oXM45oeCwX3MpnZWDNrzXzfAnwCb6DoAeAzmZddBCyLpoX145yb75wb55ybgHe5udo591ka8FiY2f5mdkD2e+CTwOPAPXjHABrkWAA4554HnjGziZlN04Hf06DHI+N8hlIyUONjoRmqZTKzY/EGP5rwTo53OOf+2cyOxOu9jgF6gAucc29E19L6MrOTgf/rnJvZiMci8zPfnXk4Gvipc+5qMzsIuAMYj7es9TnOuV0RNbOuzOx4vIH2twBPAReT+ZuhwY5H5oS/HTjSOfdKZltN/28ouIuIpJDSMiIiKaTgLiKSQgruIiIppOAuIpJCCu4iIimk4C4ikkIK7iIiKfT/AXIuZgo6S4HMAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(x, y)\n",
    "pred_y = w * x + b\n",
    "plt.plot(x, pred_y, c='r')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
